package project;

import project.environments.DynamicEnvClass;
import project.environments.EnvironmentException;
import project.environments.StaticEnvClass;
import project.parser.EvalException;
import project.parser.ParseException;
import project.parser.Parser;
import project.parser.TypecheckException;
import project.parser.ast.Prog;
import project.parser.tokenizer.Tokenizer;

import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		Parser parser = new Parser(new Tokenizer(new InputStreamReader(System.in)));
		try {
			Prog prog = parser.parseProg();
			prog.typecheck(new StaticEnvClass());
			prog.evaluate(new DynamicEnvClass());
		} catch (ParseException e) {
			System.out.println("Parse error: " + e.getMessage());
		} catch (TypecheckException | EnvironmentException e) {
			System.out.println("Typecheck error: " + e.getMessage());
		} catch (EvalException | ArithmeticException e) {
			System.out.println("Runtime error: " + e.getMessage());
		} catch (Exception e) {
			System.out.println(e.toString());
		}
	}
}
